package www.openteam.com.adapter.PrdctnMngmnt;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import www.openteam.com.R;
import www.openteam.com.bean.OutFactoryMsg;

/**
 * Created by Administrator on 2019-06-12.
 */

public class SendRCKSearchAdp extends RecyclerView.Adapter<SendRCKSearchAdp.ViewHolder> {

    Context context;
    List<OutFactoryMsg.DataBeanX.DataBean> dataBeanList = new ArrayList<>();
    SendRCKSearchClickBack sendRCKSearchClickBack;
    double mClickTime =0;

    public interface SendRCKSearchClickBack{
        void postdata(OutFactoryMsg.DataBeanX.DataBean dataBean);
    }

    public SendRCKSearchAdp(Context context, List<OutFactoryMsg.DataBeanX.DataBean> dataBeanList) {
        this.context = context;
        this.dataBeanList = dataBeanList;
    }

    public void setSendRCKSearchClickBack(SendRCKSearchClickBack sendRCKSearchClickBack) {
        this.sendRCKSearchClickBack = sendRCKSearchClickBack;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_sendrck_search, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final OutFactoryMsg.DataBeanX.DataBean dataBean = dataBeanList.get(position);
        holder.sendrckShOutfactorycode.setText(dataBean.getCode());
        holder.sendrckShOutfactoryName.setText(dataBean.getName());
        holder.sendrckShOutfactoryAd.setText(dataBean.getAddress());
        holder.sendrckShPhone.setText(dataBean.getTel());
        holder.sendrckShFax.setText(dataBean.getFax());
        holder.sendrckShCurrency.setText(dataBean.getMoneytypename());
        holder.sendrckShPayType.setText(dataBean.getPaytimename());
        holder.sendrckShline.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (System.currentTimeMillis() - mClickTime <600) {
                    if (null!=sendRCKSearchClickBack){
                        sendRCKSearchClickBack.postdata(dataBean);
                    }
                } else {
                    mClickTime = System.currentTimeMillis();
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return dataBeanList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.sendrckSh_outfactorycode)
        TextView sendrckShOutfactorycode;
        @Bind(R.id.sendrckSh_outfactoryName)
        TextView sendrckShOutfactoryName;
        @Bind(R.id.sendrckSh_outfactoryAd)
        TextView sendrckShOutfactoryAd;
        @Bind(R.id.sendrckSh_phone)
        TextView sendrckShPhone;
        @Bind(R.id.sendrckSh_fax)
        TextView sendrckShFax;
        @Bind(R.id.sendrckSh_currency)
        TextView sendrckShCurrency;
        @Bind(R.id.sendrckSh_payType)
        TextView sendrckShPayType;
        @Bind(R.id.sendrckSh_line)
        LinearLayout sendrckShline;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
